<?php
//=======================================
//###################################
// Kayako Web Solutions
//
// Source Copyright 2001-2004 Kayako Infotech Ltd.
// Unauthorized reproduction is not allowed
// License Number: $%LICENSE%$
// $Author: vshoor $ ($Date: 2007/02/28 20:06:18 $)
// $RCSfile: setup.php,v $ : $Revision: 1.25 $ 
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//
//###################################
//=======================================

if (!defined("INSWIFT")) {
	trigger_error("Unable to process $PHP_SELF", E_USER_ERROR);
}

require_once ("./modules/tickets/tickets.php");
require_once ("./modules/tickets/functions_tickets.php");
require_once ("./modules/tickets/functions_ticketsui.php");
require_once ("./modules/tickets/functions_views.php");

/**
* Called when the module is to be installed
*/
function _tickets_install($action, $page = '') {
	global $_SWIFT, $__LANG, $dbCore;

	if ($action == "getpages")
	{
		return "1";
	} else if ($action == "buildpage") {
		$_SWIFT["query"]["create"]["ticketpriorities"] = "CREATE TABLE ". TABLE_PREFIX ."ticketpriorities (
																		priorityid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		title VARCHAR(255) NOT NULL DEFAULT '',
																		displayorder INT UNSIGNED NOT NULL DEFAULT '0',
																		type ENUM('public', 'private') NOT NULL DEFAULT 'public',
																		frcolorcode VARCHAR(100) NOT NULL DEFAULT '',
																		bgcolorcode VARCHAR(100) NOT NULL DEFAULT '',
																		iscustom SMALLINT(1) UNSIGNED NOT NULL DEFAULT '1',
																		PRIMARY KEY (priorityid)
																	);";

		$_SWIFT["query"]["create"]["ticketstatus"] = "CREATE TABLE ". TABLE_PREFIX ."ticketstatus (
																		ticketstatusid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		title VARCHAR(255) NOT NULL DEFAULT '',
																		displayorder INT UNSIGNED NOT NULL DEFAULT '0',
																		iscustom SMALLINT(1) UNSIGNED NOT NULL DEFAULT '1',
																		displayinmainlist SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		ismaster SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		statustype SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		displaycount SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		statuscolor VARCHAR(50) NOT NULL DEFAULT '',
																		departmentid INT UNSIGNED NOT NULL DEFAULT '0',
																		type ENUM('public', 'private') NOT NULL DEFAULT 'public',
																		resetduetime SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (ticketstatusid)
																	);";

		$_SWIFT["query"]["create"]["tickets"] = "CREATE TABLE ". TABLE_PREFIX ."tickets (
																		ticketid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketmaskid VARCHAR(20) NOT NULL DEFAULT '',
																		departmentid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketstatusid INT UNSIGNED NOT NULL DEFAULT '0',
																		priorityid INT UNSIGNED NOT NULL DEFAULT '0',
																		emailqueueid INT UNSIGNED NOT NULL DEFAULT '0',
																		userid INT UNSIGNED NOT NULL DEFAULT '0',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		ownerstaffid INT UNSIGNED NOT NULL DEFAULT '0',
																		assignstatus SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		
																		fullname VARCHAR(255) NOT NULL DEFAULT '',
																		email VARCHAR(180) NOT NULL DEFAULT '',
																		lastreplier VARCHAR(255) NOT NULL DEFAULT '',
																		replyto VARCHAR(255) NOT NULL DEFAULT '',
																		subject VARCHAR(150) NOT NULL DEFAULT '',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		lastactivity INT UNSIGNED NOT NULL DEFAULT '0',
																		laststaffreplytime INT UNSIGNED NOT NULL DEFAULT '0',
																		slaplanid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketslaplanid INT UNSIGNED NOT NULL DEFAULT '0',
																		duetime INT UNSIGNED NOT NULL DEFAULT '0',
																		totalreplies INT UNSIGNED NOT NULL DEFAULT '0',
																		ipaddress VARCHAR(120) NOT NULL DEFAULT '',
																		flagtype SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		hasnotes SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		hasattachments SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		isemailed SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		edited SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		editedbystaffid INT UNSIGNED NOT NULL DEFAULT '0',
																		editeddateline INT UNSIGNED NOT NULL DEFAULT '0',
																		creator SMALLINT(1) NOT NULL DEFAULT '0',
																		charset VARCHAR(100) NOT NULL DEFAULT '',
																		transferencoding VARCHAR(50) NOT NULL DEFAULT '',
																		timeworked INT UNSIGNED NOT NULL DEFAULT '0',
																		dateicon INT UNSIGNED NOT NULL DEFAULT '0',
																		lastpostid INT UNSIGNED NOT NULL DEFAULT '0',
																		firstpostid INT UNSIGNED NOT NULL DEFAULT '0',
																		tgroupid INT UNSIGNED NOT NULL DEFAULT '0',
																		messageid VARCHAR(15) NOT NULL DEFAULT '',
																		escalationruleid INT UNSIGNED NOT NULL DEFAULT '0',
																		hasdraft SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		hasbilling SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		isphonecall SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		isescalated SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		phoneno VARCHAR(255) NOT NULL DEFAULT '',
																		autoclosetimeline INT UNSIGNED NOT NULL DEFAULT '0',
																		islabeled SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		lastuserreplytime INT UNSIGNED NOT NULL DEFAULT '0',
																		escalatedtime INT UNSIGNED NOT NULL DEFAULT '0',
																		followupcount INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (ticketid),
																		KEY ticketcount (departmentid, ticketstatusid, ownerstaffid),
																		KEY tickets1 (userid),
																		KEY tickets2 (slaplanid, duetime, ticketstatusid),
																		KEY tickets3 (departmentid, ticketstatusid, lastactivity),
																		KEY tickets4 (email, subject),
																		KEY tickets5 (departmentid, ticketstatusid, userid),
																		KEY tickets6 (departmentid, ticketstatusid, duetime),
																		KEY tickets7 (dateline),
																		KEY tickets8 (departmentid, ticketstatusid, lastuserreplytime)
																	);";

		$_SWIFT["query"]["create"]["ticketposts"] = "CREATE TABLE ". TABLE_PREFIX ."ticketposts (
																		ticketpostid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		userid INT UNSIGNED NOT NULL DEFAULT '0',
																		fullname VARCHAR(255) NOT NULL DEFAULT '',
																		email VARCHAR(255) NOT NULL DEFAULT '',
																		emailto VARCHAR(255) NOT NULL DEFAULT '',
																		subject VARCHAR(255) NOT NULL DEFAULT '',
																		ipaddress VARCHAR(255) NOT NULL DEFAULT '',
																		hasattachments SMALLINT(1) NOT NULL DEFAULT '0',
																		edited SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		editedbystaffid INT UNSIGNED NOT NULL DEFAULT '0',
																		editeddateline INT UNSIGNED NOT NULL DEFAULT '0',
																		creator SMALLINT(1) NOT NULL DEFAULT '0',
																		ishtml SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		isemailed SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		contents MEDIUMTEXT,
																		contenthash VARCHAR(32) NOT NULL DEFAULT '',
																		subjecthash VARCHAR(32) NOT NULL DEFAULT '',
																		PRIMARY KEY (ticketpostid),
																		KEY ticketposts1 (ticketid, staffid),
																		KEY ticketposts2 (email, subjecthash),
																		KEY ticketposts3 (creator, staffid, dateline)
																	);";

		$_SWIFT["query"]["create"]["ticketmessageids"] = "CREATE TABLE ". TABLE_PREFIX ."ticketmessageids (
																		ticketmessageid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		messageid VARCHAR(15) NOT NULL DEFAULT '',
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketpostid INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (ticketmessageid),
																		KEY ticketmessageids1 (messageid, ticketid),
																		KEY ticketmessageids2 (dateline)
																	);";

		$_SWIFT["query"]["create"]["ticketpostlocks"] = "CREATE TABLE ". TABLE_PREFIX ."ticketpostlocks (
																		ticketpostlockid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		contents MEDIUMTEXT,
																		PRIMARY KEY (ticketpostlockid),
																		KEY ticketpostlocks1 (ticketid, staffid),
																		KEY ticketpostlocks2 (dateline)
																	);";

		$_SWIFT["query"]["create"]["ticketdrafts"] = "CREATE TABLE ". TABLE_PREFIX ."ticketdrafts (
																		ticketdraftid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		contents MEDIUMTEXT,
																		PRIMARY KEY (ticketdraftid),
																		UNIQUE KEY ticketdrafts1 (ticketid)
																	);";

		$_SWIFT["query"]["create"]["ticketviews"] = "CREATE TABLE ". TABLE_PREFIX ."ticketviews (
																		ticketviewid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		title VARCHAR(255) NOT NULL DEFAULT '',
																		viewtype SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		viewalltickets SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		viewunassigned SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		viewassigned SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		sortby SMALLINT(3) UNSIGNED NOT NULL DEFAULT '0',
																		sortorder SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		ismaster INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketsperpage INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (ticketviewid)
																	);";

		$_SWIFT["query"]["create"]["ticketviewfields"] = "CREATE TABLE ". TABLE_PREFIX ."ticketviewfields (
																		ticketviewfieldid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketviewid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketviewfieldtype SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		customfieldid INT UNSIGNED NOT NULL DEFAULT '0',
																		fieldlinkid SMALLINT(3) UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (ticketviewfieldid),
																		KEY ticketviewfields1 (ticketviewid)
																	);";

		$_SWIFT["query"]["create"]["ticketsearches"] = "CREATE TABLE ". TABLE_PREFIX ."ticketsearches (
																		ticketsearchid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		keywords VARCHAR(255) NOT NULL DEFAULT '',
																		resultscount INT UNSIGNED NOT NULL DEFAULT '0',
																		timetaken FLOAT UNSIGNED NOT NULL DEFAULT '0',
																		ticketidlist MEDIUMTEXT,
																		relevancelist MEDIUMTEXT,
																		rejectedwords VARCHAR(255) NOT NULL DEFAULT '',
																		ticketfilterid INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (ticketsearchid),
																		KEY ticketsearches1 (dateline)
																	);";

		$_SWIFT["query"]["create"]["ticketpostindex"] = "CREATE TABLE ". TABLE_PREFIX ."ticketpostindex (
																		ticketwordid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketpostid INT UNSIGNED NOT NULL DEFAULT '0',
																		insubject SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		UNIQUE KEY ticketpostindex (ticketwordid, ticketpostid, insubject)
																	);";

		$_SWIFT["query"]["create"]["ticketwords"] = "CREATE TABLE ". TABLE_PREFIX ."ticketwords (
																		ticketwordid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		contents CHAR(50) NOT NULL DEFAULT '',
																		PRIMARY KEY (ticketwordid),
																		UNIQUE KEY ticketwords (contents)
																	);";

		$_SWIFT["query"]["create"]["auditlogs"] = "CREATE TABLE ". TABLE_PREFIX ."auditlogs (
																		auditlogid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		departmentid INT UNSIGNED NOT NULL DEFAULT '0',
																		userid INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		logtype SMALLINT(3) UNSIGNED NOT NULL DEFAULT '0',
																		actiontype SMALLINT(3) UNSIGNED NOT NULL DEFAULT '0',
																		actionmsg VARCHAR(255) NOT NULL DEFAULT '',
																		PRIMARY KEY (auditlogid),
																		KEY auditlogs1 (ticketid, actiontype),
																		KEY auditlogs2 (dateline, staffid)
																	);";

		$_SWIFT["query"]["create"]["ticketmergelog"] = "CREATE TABLE ". TABLE_PREFIX ."ticketmergelog (
																		mergelogid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		oldticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		oldticketmaskid VARCHAR(20) NOT NULL DEFAULT '',
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (mergelogid),
																		KEY ticketmergelog1 (oldticketid),
																		KEY ticketmergelog2 (oldticketmaskid)
																	);";

		$_SWIFT["query"]["create"]["attachments"] = "CREATE TABLE ". TABLE_PREFIX ."attachments (
																		attachmentid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketpostid INT UNSIGNED NOT NULL DEFAULT '0',
																		downloaditemid INT UNSIGNED NOT NULL DEFAULT '0',
																		filename VARCHAR(255) NOT NULL DEFAULT '',
																		filesize INT UNSIGNED NOT NULL DEFAULT '0',
																		filetype VARCHAR(150) NOT NULL DEFAULT '',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		attachmenttype SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		storefilename VARCHAR(255) NOT NULL DEFAULT '',
																		PRIMARY KEY (attachmentid),
																		KEY attachments1 (ticketpostid)
																	);";

		$_SWIFT["query"]["create"]["attachmentchunks"] = "CREATE TABLE ". TABLE_PREFIX ."attachmentchunks (
																		chunkid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		attachmentid INT UNSIGNED NOT NULL DEFAULT '0',
																		contents MEDIUMBLOB,
																		PRIMARY KEY (chunkid),
																		KEY attachmentchunks1 (attachmentid)
																	);";

		$_SWIFT["query"]["create"]["attachmenttypes"] = "CREATE TABLE ". TABLE_PREFIX ."attachmenttypes (
																		attachmenttypeid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		extension VARCHAR(10) NOT NULL DEFAULT '',
																		maxsize INT UNSIGNED NOT NULL DEFAULT '0',
																		mimetype VARCHAR(150) NOT NULL DEFAULT '',
																		PRIMARY KEY (attachmenttypeid)
																	);";

		$_SWIFT["query"]["create"]["ticketnotes"] = "CREATE TABLE ". TABLE_PREFIX ."ticketnotes (
																		ticketnoteid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		typeid INT UNSIGNED NOT NULL DEFAULT '0',
																		notetype SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		forstaffid INT UNSIGNED NOT NULL DEFAULT '0',
																		bystaffid INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		notes TEXT,
																		PRIMARY KEY (ticketnoteid),
																		KEY ticketnotes1 (typeid, notetype)
																	);";

		$_SWIFT["query"]["create"]["ticketemails"] = "CREATE TABLE ". TABLE_PREFIX ."ticketemails (
																		ticketemailid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		email VARCHAR(255) NOT NULL DEFAULT '',
																		PRIMARY KEY (ticketemailid),
																		UNIQUE KEY ticketemails1 (email)
																	);";

		$_SWIFT["query"]["create"]["ticketrecipients"] = "CREATE TABLE ". TABLE_PREFIX ."ticketrecipients (
																		recipientid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketemailid INT UNSIGNED NOT NULL DEFAULT '0',
																		recipienttype SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (recipientid),
																		UNIQUE KEY ticketrecipients (ticketid, ticketemailid)
																	);";

		$_SWIFT["query"]["create"]["tickettimetrack"] = "CREATE TABLE ". TABLE_PREFIX ."tickettimetrack (
																		timetrackid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		creatorstaffid INT UNSIGNED NOT NULL DEFAULT '0',
																		timespent INT UNSIGNED NOT NULL DEFAULT '0',
																		timebillable INT UNSIGNED NOT NULL DEFAULT '0',
																		forstaffid INT UNSIGNED NOT NULL DEFAULT '0',
																		notes MEDIUMTEXT,
																		PRIMARY KEY (timetrackid),
																		KEY tickettimetrack (ticketid)
																	);";
																			
		$_SWIFT["query"]["create"]["predefinedcategories"] = "CREATE TABLE ". TABLE_PREFIX ."predefinedcategories (
																		predefinedcategoryid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		parentcategoryid INT UNSIGNED NOT NULL DEFAULT '0',
																		categorytype SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		title VARCHAR(255) NOT NULL DEFAULT '',
																		PRIMARY KEY (predefinedcategoryid),
																		KEY predefinedcategory1 (parentcategoryid),
																		KEY predefinedcategory2 (categorytype, staffid)
																	);";
																	
		$_SWIFT["query"]["create"]["predefinedreplies"] = "CREATE TABLE ". TABLE_PREFIX ."predefinedreplies (
																		predefinedreplyid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		predefinedcategoryid INT UNSIGNED NOT NULL DEFAULT '0',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		subject VARCHAR(255) NOT NULL DEFAULT '',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (predefinedreplyid),
																		KEY predefinedreply1 (predefinedcategoryid),
																		KEY predefinedreply2 (staffid)
																	);";

		$_SWIFT["query"]["create"]["predefinedreplydata"] = "CREATE TABLE ". TABLE_PREFIX ."predefinedreplydata (
																		predefinedreplydataid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		predefinedreplyid INT UNSIGNED NOT NULL DEFAULT '0',
																		contents MEDIUMTEXT,
																		PRIMARY KEY (predefinedreplydataid),
																		KEY predefinedreplydata1 (predefinedreplyid)
																	);";

		$_SWIFT["query"]["create"]["alertrules"] = "CREATE TABLE ". TABLE_PREFIX ."alertrules (
																		alertruleid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		alertscope SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		departmentid INT UNSIGNED NOT NULL DEFAULT '0',
																		priorityid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketstatusid INT UNSIGNED NOT NULL DEFAULT '0',
																		alerttype SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		execassign SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		title VARCHAR(255) NOT NULL DEFAULT '',
																		PRIMARY KEY (alertruleid),
																		KEY alertrules1 (alertscope, staffid)
																	);";

		$_SWIFT["query"]["create"]["alertactions"] = "CREATE TABLE ". TABLE_PREFIX ."alertactions (
																		alertactionid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		alertruleid INT UNSIGNED NOT NULL DEFAULT '0',
																		actiontype SMALLINT(3) UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (alertactionid),
																		KEY alertactions1 (actiontype)
																	);";

		$_SWIFT["query"]["create"]["slaplans"] = "CREATE TABLE ". TABLE_PREFIX ."slaplans (
																		slaplanid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		departmentid INT UNSIGNED NOT NULL DEFAULT '0',
																		slascheduleid INT UNSIGNED NOT NULL DEFAULT '0',
																		title VARCHAR(255) NOT NULL DEFAULT '',
																		overduehrs FLOAT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (slaplanid),
																		KEY slaplans1 (departmentid),
																		KEY slaplans2 (slascheduleid)
																	);";

		$_SWIFT["query"]["create"]["slaplanstatuslink"] = "CREATE TABLE ". TABLE_PREFIX ."slaplanstatuslink (
																		planstatuslinkid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		slaplanid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketstatusid INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (planstatuslinkid),
																		UNIQUE KEY (slaplanid, ticketstatusid)
																	);";

		$_SWIFT["query"]["create"]["slaplanprioritylink"] = "CREATE TABLE ". TABLE_PREFIX ."slaplanprioritylink (
																		planprioritylinkid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		slaplanid INT UNSIGNED NOT NULL DEFAULT '0',
																		priorityid INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (planprioritylinkid),
																		UNIQUE KEY (slaplanid, priorityid)
																	);";

		$_SWIFT["query"]["create"]["slaschedules"] = "CREATE TABLE ". TABLE_PREFIX ."slaschedules (
																		slascheduleid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		title VARCHAR(255) NOT NULL DEFAULT '',
																		sunday_enabled SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		sunday_open VARCHAR(6) NOT NULL DEFAULT '00:00',
																		sunday_close VARCHAR(6) NOT NULL DEFAULT '00:00',
																		monday_enabled SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		monday_open VARCHAR(6) NOT NULL DEFAULT '00:00',
																		monday_close VARCHAR(6) NOT NULL DEFAULT '00:00',
																		tuesday_enabled SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		tuesday_open VARCHAR(6) NOT NULL DEFAULT '00:00',
																		tuesday_close VARCHAR(6) NOT NULL DEFAULT '00:00',
																		wednesday_enabled SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		wednesday_open VARCHAR(6) NOT NULL DEFAULT '00:00',
																		wednesday_close VARCHAR(6) NOT NULL DEFAULT '00:00',
																		thursday_enabled SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		thursday_open VARCHAR(6) NOT NULL DEFAULT '00:00',
																		thursday_close VARCHAR(6) NOT NULL DEFAULT '00:00',
																		friday_enabled SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		friday_open VARCHAR(6) NOT NULL DEFAULT '00:00',
																		friday_close VARCHAR(6) NOT NULL DEFAULT '00:00',
																		saturday_enabled SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		saturday_open VARCHAR(6) NOT NULL DEFAULT '00:00',
																		saturday_close VARCHAR(6) NOT NULL DEFAULT '00:00',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (slascheduleid)
																	);";

		$_SWIFT["query"]["create"]["escalationrules"] = "CREATE TABLE ". TABLE_PREFIX ."escalationrules (
																		escalationruleid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		slaplanid INT UNSIGNED NOT NULL DEFAULT '0',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		priorityid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketstatusid INT UNSIGNED NOT NULL DEFAULT '0',
																		departmentid INT UNSIGNED NOT NULL DEFAULT '0',
																		title VARCHAR(255) NOT NULL DEFAULT '',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (escalationruleid),
																		KEY escalationrules1 (slaplanid)
																	);";

		$_SWIFT["query"]["create"]["ticketlocks"] = "CREATE TABLE ". TABLE_PREFIX ."ticketlocks (
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		lockstaffid INT UNSIGNED NOT NULL DEFAULT '0',
																		lockdateline INT UNSIGNED NOT NULL DEFAULT '0',
																		UNIQUE KEY ticketlocks1 (ticketid)
																	);";

		// ======= ADDED IN v3.00.26 =======

		$_SWIFT["query"]["create"]["ticketlabels"] = "CREATE TABLE ". TABLE_PREFIX ."ticketlabels (
																		ticketlabelid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		title VARCHAR(255) NOT NULL DEFAULT '',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		labeltype ENUM('public', 'private') NOT NULL DEFAULT 'public',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (ticketlabelid),
																		KEY ticketlabels1 (labeltype, staffid)
																	);";

		$_SWIFT["query"]["create"]["ticketlabellinks"] = "CREATE TABLE ". TABLE_PREFIX ."ticketlabellinks (
																		ticketlabellinkid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketlabelid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (ticketlabellinkid),
																		UNIQUE KEY ticketlabellinks1 (ticketlabelid, ticketid),
																		KEY ticketlabellinks2 (ticketid)
																	);";

		// ======= ADDED IN v3.00.80 =======

		$_SWIFT["query"]["create"]["ticketfilters"] = "CREATE TABLE ". TABLE_PREFIX ."ticketfilters (
																		ticketfilterid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		filtertype ENUM('public', 'private') NOT NULL DEFAULT 'public',
																		title VARCHAR(255) NOT NULL DEFAULT '',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		filteroptions ENUM('all', 'any') NOT NULL DEFAULT 'all',
																		PRIMARY KEY (ticketfilterid),
																		KEY ticketfilters1 (filtertype, staffid)
																	);";

		$_SWIFT["query"]["create"]["ticketfilterfields"] = "CREATE TABLE ". TABLE_PREFIX ."ticketfilterfields (
																		ticketfilterfieldid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		ticketfilterid INT UNSIGNED NOT NULL DEFAULT '0',
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		fieldtitle VARCHAR(255) NOT NULL DEFAULT '',
																		fieldoper INT UNSIGNED NOT NULL DEFAULT '0',
																		fieldvalue VARCHAR(255) NOT NULL DEFAULT '',
																		PRIMARY KEY (ticketfilterfieldid),
																		KEY ticketfilterfields (ticketfilterid)
																	);";

		// ======= ADDED IN v3.00.95 & UPDATED IN v3.02.00 =======

		$_SWIFT["query"]["create"]["ticketfollowup"] = "CREATE TABLE ". TABLE_PREFIX ."ticketfollowup (
																		ticketfollowupid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		execdateline INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		staffid INT UNSIGNED NOT NULL DEFAULT '0',
																		ownerstaffid INT NOT NULL DEFAULT '0',
																		departmentid INT NOT NULL DEFAULT '0',
																		ticketstatusid INT NOT NULL DEFAULT '0',
																		priorityid INT NOT NULL DEFAULT '0',
																		duedateline INT NOT NULL DEFAULT '0',
																		markasoverdue SMALLINT(3) NOT NULL DEFAULT '0',
																		timeworked INT NOT NULL DEFAULT '0',
																		donote SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		notetype SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		ticketnotes MEDIUMTEXT,
																		doreply SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		replycontents MEDIUMTEXT,
																		doforward SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		forwardemailto VARCHAR(255) NOT NULL DEFAULT '',
																		forwardcontents MEDIUMTEXT,
																		PRIMARY KEY (ticketfollowupid),
																		KEY ticketfollowup1 (ticketid),
																		KEY ticketfollowup2 (execdateline)
																	);";

		// ======= ADDED IN v3.00.98 =======

		$_SWIFT["query"]["create"]["escalationpaths"] = "CREATE TABLE ". TABLE_PREFIX ."escalationpaths (
																		escalationpathid INT UNSIGNED NOT NULL AUTO_INCREMENT,
																		dateline INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketid INT UNSIGNED NOT NULL DEFAULT '0',
																		slaplanid INT UNSIGNED NOT NULL DEFAULT '0',
																		escalationruleid INT UNSIGNED NOT NULL DEFAULT '0',
																		ownerstaffid INT UNSIGNED NOT NULL DEFAULT '0',
																		departmentid INT UNSIGNED NOT NULL DEFAULT '0',
																		ticketstatusid INT UNSIGNED NOT NULL DEFAULT '0',
																		priorityid INT UNSIGNED NOT NULL DEFAULT '0',
																		flagtype SMALLINT(1) UNSIGNED NOT NULL DEFAULT '0',
																		PRIMARY KEY (escalationpathid),
																		KEY escalationpaths1 (ticketid)
																	);";

		$_SWIFT["query"]["alter"]["ticketlocks"][] = "ALTER TABLE `". TABLE_PREFIX ."ticketlocks` TYPE = HEAP;";

		// Register the module
		$_SWIFT["query"]["insert"]["settings"][0] = "INSERT INTO `". TABLE_PREFIX ."settings`(`section`, `vkey`, `data`) VALUES ('registeredmodules', 'tickets', '1')";

		// Ticket Views
		$_SWIFT["query"]["insert"]["ticketviews"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviews`(`title`, `viewtype`, `staffid`, `viewalltickets`, `viewunassigned`, `viewassigned`, `sortby`, `sortorder`, `ismaster`, `dateline`, `ticketsperpage`) VALUES ('". addslashes($__LANG["defaultview"]) ."', '". VIEW_PUBLIC ."', '0', '0', '1', '1', '". FIELD_LASTACTIVITY ."', '2', '1', '". DATENOW ."', '20')";
		$_SWIFT["query"]["insert"]["ticketviews"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviews`(`title`, `viewtype`, `staffid`, `viewalltickets`, `viewunassigned`, `viewassigned`, `sortby`, `sortorder`, `ismaster`, `dateline`, `ticketsperpage`) VALUES ('". addslashes($__LANG["alltickets"]) ."', '". VIEW_PUBLIC ."', '0', '1', '1', '1', '". FIELD_LASTACTIVITY ."', '2', '0', '". DATENOW ."', '20')";

		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('1', '". VIEWFIELD_LINK ."', '0', '". FIELD_DATEICON ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('1', '". VIEWFIELD_LINK ."', '0', '". FIELD_NOTESTATUS ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('1', '". VIEWFIELD_LINK ."', '0', '". FIELD_SUBJECT ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('1', '". VIEWFIELD_LINK ."', '0', '". FIELD_TICKETID ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('1', '". VIEWFIELD_LINK ."', '0', '". FIELD_LASTREPLIER ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('1', '". VIEWFIELD_LINK ."', '0', '". FIELD_REPLIES ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('1', '". VIEWFIELD_LINK ."', '0', '". FIELD_LASTACTIVITY ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('1', '". VIEWFIELD_LINK ."', '0', '". FIELD_DUEDATE ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('1', '". VIEWFIELD_LINK ."', '0', '". FIELD_FLAGS ."')";

		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('2', '". VIEWFIELD_LINK ."', '0', '". FIELD_DATEICON ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('2', '". VIEWFIELD_LINK ."', '0', '". FIELD_NOTESTATUS ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('2', '". VIEWFIELD_LINK ."', '0', '". FIELD_SUBJECT ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('2', '". VIEWFIELD_LINK ."', '0', '". FIELD_TICKETID ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('2', '". VIEWFIELD_LINK ."', '0', '". FIELD_LASTREPLIER ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('2', '". VIEWFIELD_LINK ."', '0', '". FIELD_REPLIES ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('2', '". VIEWFIELD_LINK ."', '0', '". FIELD_LASTACTIVITY ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('2', '". VIEWFIELD_LINK ."', '0', '". FIELD_DUEDATE ."')";
		$_SWIFT["query"]["insert"]["ticketviewfields"][] = "INSERT INTO `". TABLE_PREFIX ."ticketviewfields`(`ticketviewid`, `ticketviewfieldtype`, `customfieldid`, `fieldlinkid`) VALUES ('2', '". VIEWFIELD_LINK ."', '0', '". FIELD_FLAGS ."')";

		// Insert Default Ticket Status
		$_SWIFT["query"]["insert"]["ticketstatus"][] = "INSERT INTO `". TABLE_PREFIX ."ticketstatus` (`title`, `displayorder`, `iscustom`, `displayinmainlist`, `ismaster`, `statustype`, `displaycount`, `statuscolor`, `departmentid`, `type`, `resetduetime`) VALUES ('". addslashes($__LANG["statusopen"]) ."', '1', '0', '1', '1', '". STATUS_OPEN ."', '1', '#5C83B4', '0', 'public', '0');";
		$_SWIFT["query"]["insert"]["ticketstatus"][] = "INSERT INTO `". TABLE_PREFIX ."ticketstatus` (`title`, `displayorder`, `iscustom`, `displayinmainlist`, `ismaster`, `statustype`, `displaycount`, `statuscolor`, `departmentid`, `type`, `resetduetime`) VALUES ('". addslashes($__LANG["statusonhold"]) ."', '2', '0', '0', '1', '". STATUS_ONHOLD ."', '0', '#8BB467', '0', 'public', '1');";
		$_SWIFT["query"]["insert"]["ticketstatus"][] = "INSERT INTO `". TABLE_PREFIX ."ticketstatus` (`title`, `displayorder`, `iscustom`, `displayinmainlist`, `ismaster`, `statustype`, `displaycount`, `statuscolor`, `departmentid`, `type`, `resetduetime`) VALUES ('". addslashes($__LANG["statusclosed"]) ."', '3', '0', '0', '1', '". STATUS_CLOSED ."', '0', '#CF5D60', '0', 'public', '1');";

		// Insert Default Ticket Priorities
		$_SWIFT["query"]["insert"]["ticketpriorities"][] = "INSERT INTO `". TABLE_PREFIX ."ticketpriorities` (`title`, `displayorder`, `type`, `frcolorcode`, `bgcolorcode`, `iscustom`) VALUES ('". addslashes($__LANG["prlow"]) ."', '1', 'public', '#8A8A8A', '', '0');";
		$_SWIFT["query"]["insert"]["ticketpriorities"][] = "INSERT INTO `". TABLE_PREFIX ."ticketpriorities` (`title`, `displayorder`, `type`, `frcolorcode`, `bgcolorcode`, `iscustom`) VALUES ('". addslashes($__LANG["prmedium"]) ."', '2', 'public', '#000000', '', '0');";
		$_SWIFT["query"]["insert"]["ticketpriorities"][] = "INSERT INTO `". TABLE_PREFIX ."ticketpriorities` (`title`, `displayorder`, `type`, `frcolorcode`, `bgcolorcode`, `iscustom`) VALUES ('". addslashes($__LANG["prhigh"]) ."', '3', 'public', '#F07D18', '', '0');";
		$_SWIFT["query"]["insert"]["ticketpriorities"][] = "INSERT INTO `". TABLE_PREFIX ."ticketpriorities` (`title`, `displayorder`, `type`, `frcolorcode`, `bgcolorcode`, `iscustom`) VALUES ('". addslashes($__LANG["prurgent"]) ."', '4', 'public', '#E826C6', '', '0');";
		$_SWIFT["query"]["insert"]["ticketpriorities"][] = "INSERT INTO `". TABLE_PREFIX ."ticketpriorities` (`title`, `displayorder`, `type`, `frcolorcode`, `bgcolorcode`, `iscustom`) VALUES ('". addslashes($__LANG["premergency"]) ."', '5', 'public', '#E06161', '', '0');";
		$_SWIFT["query"]["insert"]["ticketpriorities"][] = "INSERT INTO `". TABLE_PREFIX ."ticketpriorities` (`title`, `displayorder`, `type`, `frcolorcode`, `bgcolorcode`, `iscustom`) VALUES ('". addslashes($__LANG["prcritical"]) ."', '6', 'public', '#FF0000', '#FFF6F5', '0');";

		$_SWIFT["query"]["insert"]["tgroupassigns"][] = "INSERT INTO `". TABLE_PREFIX ."tgroupassigns` (`toassignid`, `type`, `tgroupid`) VALUES ('1', '". TGROUP_PRIORITY ."', '1');";
		$_SWIFT["query"]["insert"]["tgroupassigns"][] = "INSERT INTO `". TABLE_PREFIX ."tgroupassigns` (`toassignid`, `type`, `tgroupid`) VALUES ('2', '". TGROUP_PRIORITY ."', '1');";
		$_SWIFT["query"]["insert"]["tgroupassigns"][] = "INSERT INTO `". TABLE_PREFIX ."tgroupassigns` (`toassignid`, `type`, `tgroupid`) VALUES ('3', '". TGROUP_PRIORITY ."', '1');";
		$_SWIFT["query"]["insert"]["tgroupassigns"][] = "INSERT INTO `". TABLE_PREFIX ."tgroupassigns` (`toassignid`, `type`, `tgroupid`) VALUES ('4', '". TGROUP_PRIORITY ."', '1');";
		$_SWIFT["query"]["insert"]["tgroupassigns"][] = "INSERT INTO `". TABLE_PREFIX ."tgroupassigns` (`toassignid`, `type`, `tgroupid`) VALUES ('5', '". TGROUP_PRIORITY ."', '1');";
		$_SWIFT["query"]["insert"]["tgroupassigns"][] = "INSERT INTO `". TABLE_PREFIX ."tgroupassigns` (`toassignid`, `type`, `tgroupid`) VALUES ('6', '". TGROUP_PRIORITY ."', '1');";

		$_SWIFT["query"]["insert"]["cron"][] = "INSERT INTO `". TABLE_PREFIX ."cron` (`nextrun`, `lastrun`, `chour`, `cminute`, `cday`, `module`, `action`, `autorun`, `name`) VALUES ('". time() ."', '". time() ."', '0', '30', '0', 'tickets', 'cron', '1', 'tickets');";

		$_SWIFT["query"]["insert"]["cron"][] = "INSERT INTO `". TABLE_PREFIX ."cron` (`nextrun`, `lastrun`, `chour`, `cminute`, `cday`, `module`, `action`, `autorun`, `name`) VALUES ('". time() ."', '". time() ."', '0', '10', '0', 'tickets', 'cronfollowup', '1', 'ticketfollowup');";


		/**
		* ###############################################
		* BUILD ALL REQUIRED CACHES
		* ###############################################
		*/
		execAllQueries();

		// ======= STATUS CACHE =======
		rebuildStatusCache();

		// ======= PRIORITY CACHE =======
		rebuildPriorityCache();

		// ======= ATTACHMENT TYPE CACHE =======
		rebuildAttachmentTypeCache();

		// ======= TICKET VIEW CACHE =======
		rebuildTicketViewsCache();
	}
}

/**
* Uninstall Routine
*/
function _tickets_uninstall()
{
	global $_SWIFT;

	$_SWIFT["query"]["drop"]["ticketpriorities"] = "DROP TABLE `". TABLE_PREFIX ."ticketpriorities`;";

	$_SWIFT["query"]["drop"]["ticketstatus"] = "DROP TABLE `". TABLE_PREFIX ."ticketstatus`;";

	$_SWIFT["query"]["drop"]["tickets"] = "DROP TABLE `". TABLE_PREFIX ."tickets`;";

	$_SWIFT["query"]["drop"]["ticketposts"] = "DROP TABLE `". TABLE_PREFIX ."ticketposts`;";

	$_SWIFT["query"]["drop"]["ticketmessageids"] = "DROP TABLE `". TABLE_PREFIX ."ticketmessageids`;";

	$_SWIFT["query"]["drop"]["ticketdrafts"] = "DROP TABLE `". TABLE_PREFIX ."ticketdrafts`;";

	$_SWIFT["query"]["drop"]["ticketviews"] = "DROP TABLE `". TABLE_PREFIX ."ticketviews`;";

	$_SWIFT["query"]["drop"]["ticketviewfields"] = "DROP TABLE `". TABLE_PREFIX ."ticketviewfields`;";

	$_SWIFT["query"]["drop"]["ticketsearches"] = "DROP TABLE `". TABLE_PREFIX ."ticketsearches`;";

	$_SWIFT["query"]["drop"]["ticketpostindex"] = "DROP TABLE `". TABLE_PREFIX ."ticketpostindex`;";

	$_SWIFT["query"]["drop"]["ticketwords"] = "DROP TABLE `". TABLE_PREFIX ."ticketwords`;";

	$_SWIFT["query"]["drop"]["auditlogs"] = "DROP TABLE `". TABLE_PREFIX ."auditlogs`;";

	$_SWIFT["query"]["drop"]["ticketmergelog"] = "DROP TABLE `". TABLE_PREFIX ."ticketmergelog`;";

	$_SWIFT["query"]["drop"]["attachments"] = "DROP TABLE `". TABLE_PREFIX ."attachments`;";

	$_SWIFT["query"]["drop"]["attachmentchunks"] = "DROP TABLE `". TABLE_PREFIX ."attachmentchunks`;";

	$_SWIFT["query"]["drop"]["attachmenttypes"] = "DROP TABLE `". TABLE_PREFIX ."attachmenttypes`;";

	$_SWIFT["query"]["drop"]["ticketnotes"] = "DROP TABLE `". TABLE_PREFIX ."ticketnotes`;";

	$_SWIFT["query"]["drop"]["ticketemails"] = "DROP TABLE `". TABLE_PREFIX ."ticketemails`;";

	$_SWIFT["query"]["drop"]["ticketrecipients"] = "DROP TABLE `". TABLE_PREFIX ."ticketrecipients`;";

	$_SWIFT["query"]["drop"]["tickettimetrack"] = "DROP TABLE `". TABLE_PREFIX ."tickettimetrack`;";

	$_SWIFT["query"]["drop"]["predefinedcategories"] = "DROP TABLE `". TABLE_PREFIX ."predefinedcategories`;";

	$_SWIFT["query"]["drop"]["predefinedreplies"] = "DROP TABLE `". TABLE_PREFIX ."predefinedreplies`;";

	$_SWIFT["query"]["drop"]["predefinedreplydata"] = "DROP TABLE `". TABLE_PREFIX ."predefinedreplydata`;";

	$_SWIFT["query"]["drop"]["alertrules"] = "DROP TABLE `". TABLE_PREFIX ."alertrules`;";

	$_SWIFT["query"]["drop"]["alertactions"] = "DROP TABLE `". TABLE_PREFIX ."alertactions`;";

	$_SWIFT["query"]["drop"]["slaplans"] = "DROP TABLE `". TABLE_PREFIX ."slaplans`;";

	$_SWIFT["query"]["drop"]["slaplanstatuslink"] = "DROP TABLE `". TABLE_PREFIX ."slaplanstatuslink`;";

	$_SWIFT["query"]["drop"]["slaplanprioritylink"] = "DROP TABLE `". TABLE_PREFIX ."slaplanprioritylink`;";

	$_SWIFT["query"]["drop"]["slaschedules"] = "DROP TABLE `". TABLE_PREFIX ."slaschedules`;";

	$_SWIFT["query"]["drop"]["escalationrules"] = "DROP TABLE `". TABLE_PREFIX ."escalationrules`;";

	$_SWIFT["query"]["delete"]["cron"] = "DELETE FROM `". TABLE_PREFIX ."cron` WHERE `module` = 'tickets';";

	$_SWIFT["query"]["delete"]["settings"][0] = "DELETE FROM `". TABLE_PREFIX ."settings` WHERE `section` = 'registeredmodules' AND `vkey` = '". MODULE_TICKETS ."';";
}
?>